package com.struts.action.product;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.spring.service.product.ProductLeibieService;
import com.struts.form.ProductAtrributeForm;
import com.struts.form.ProductLeibieForm;

public class ProductLeibieAction extends DispatchAction 
{
	private ProductLeibieService productLeibieService=null;

	/**
	 * display product leibie
	 */
	public ActionForward findProductLeibie(ActionMapping mapping, ActionForm form,
	HttpServletRequest request, HttpServletResponse response){
		Long fatherId=0L;
		if(request.getParameter("fatherId")!=null)
			fatherId=Long.parseLong(request.getParameter("fatherId"));
		request.setAttribute("productLiebei", productLeibieService.findProductLeibie("from ProductLeibie where fatherId="+fatherId));
		return mapping.findForward("productLiebei");
	}
	
	
	/**
	 * display left tree
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward findProductLeibieTree(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		request.setAttribute("productLeibieTree", productLeibieService.findProductLeibie("from ProductLeibie"));
		return mapping.findForward("productLeibieTree");
	}
	
	/**
	 * save product leibie
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward saveProductLeibie(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		ProductLeibieForm productleibieform=(ProductLeibieForm)form;
		if(productLeibieService.saveProductLeibie(productleibieform))
			return mapping.findForward("success");
		else
			return mapping.findForward("fail");
	}
	
	
	
	/**
	 * delete product leibie
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 */
	public ActionForward deleteProductLeibie(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		Long id=Long.parseLong(request.getParameter("id"));
		if(productLeibieService.deleteProductLeibie(id))
		{
			return mapping.findForward("success");
		}
		else
		{
			return mapping.findForward("fail");
		}
	}
	
	public ActionForward updateProductLeibie(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
	{
		ProductLeibieForm productleibieform=(ProductLeibieForm)form;
		if(productLeibieService.updateProductLeibie(productleibieform))
			return mapping.findForward("success");
		else
			return mapping.findForward("fail");
	}
	
	
	public ProductLeibieService getProductLeibieService() {
		return productLeibieService;
	}

	public void setProductLeibieService(ProductLeibieService productLeibieService) {
		this.productLeibieService = productLeibieService;
	}
}
